local skel = fk.CreateSkill{
  name = "tea__lanxin",
}
--local U = require "packages/utility/utility"
Fk:loadTranslationTable{
  ["tea__lanxin"] = "兰心",
  [":tea__lanxin"] = "出牌阶段或当你受到伤害后，若你的手牌数大于体力值，你可以弃置任意张手牌，然后将手牌调整至体力值。每回合限一次，若此次过程中你弃置的牌数超过获得的牌数两张及以上，你回复1点体力。",
  ["#tea__lanxin-prompt"] = "兰心：你可以弃置任意张手牌，然后将手牌调整至等于体力值",
  ["#tea__lanxin-invoke"] = "兰心：你可以弃置任意张手牌，然后将手牌调整至等于体力值",
  ["#tea__lanxin-discard"] = "兰心：你需将手牌弃至等于体力值，需要弃置 %arg 张",
}
---@type ActiveSkillSpec
local lanxin = {
  anim_type = "drawcard",
  min_card_num = 1,
  prompt = "#tea__lanxin-prompt",
  can_use = function (self, player)
    return #player:getCardIds("h") > player.hp
  end,
  target_filter = Util.FalseFunc,
  card_filter = function (self, player, to_select, selected, selected_targets)
    return table.contains(player:getCardIds("h"), to_select)
  end,
  on_use = function (self, room, skillUseEvent)
    local player = skillUseEvent.from
    room:throwCard(skillUseEvent.cards, skel.name, player, player)
    local cids, discids = {}, {}
    if not player.dead and #player:getCardIds("h") < player.hp then
      cids = player:drawCards(player.hp - #player:getCardIds("h"), skel.name)
    elseif not player.dead and #player:getCardIds("h") < player.hp then
      discids = room:askToDiscard(player, {
        min_num = player.hp - #player:getCardIds("h"),
        max_num = player.hp - #player:getCardIds("h"),
        skill_name = skel.name,
        cancelable = false,
        prompt = "#tea__lanxin-discard:::" .. tostring(#player:getCardIds("h") - player.hp)
      })
    end
    if not player.dead and #skillUseEvent.cards + #discids > #cids + 1 and player:isWounded() and player:getMark("tea__lanxin-turn") == 0 then
      room:setPlayerMark(player, "tea__lanxin-turn", 1)
      room:recover{
        who = player,
        num = 1,
        skillName = skel.name
      }
    end
  end
}
---@type TrigSkelSpec<DamageTrigFunc>
local lanxin_damage = {
  anim_type = "masochism",
  can_trigger = function (self, event, target, player, data)
    return player == target and player:hasSkill(skel.name) and #player:getCardIds("h") > player.hp
  end,
  on_cost = function (self, event, target, player, data)
    local cards = player.room:askToCards(player, {
      min_num = 1,
      skill_name = skel.name,
      max_num = 999,
      prompt = "#tea__lanxin-invoke"
    })
    if #cards > 0 then
      event:setCostData(self, { cards = cards })
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cards = event:getCostData(self).cards
    room:throwCard(cards, skel.name, player, player)
    local cids, discids = {}, {}
    if not player.dead and #player:getCardIds("h") < player.hp then
      cids = player:drawCards(player.hp - #player:getCardIds("h"), skel.name)
    elseif not player.dead and #player:getCardIds("h") < player.hp then
      discids = room:askToDiscard(player, {
        min_num = player.hp - #player:getCardIds("h"),
        max_num = player.hp - #player:getCardIds("h"),
        skill_name = skel.name,
        cancelable = false,
        prompt = "#tea__lanxin-discard:::" .. tostring(#player:getCardIds("h") - player.hp)
      })
    end
    if not player.dead and #cards + #discids > #cids + 1 and player:isWounded() and player:getMark("tea__lanxin-turn") == 0 then
      room:setPlayerMark(player, "tea__lanxin-turn", 1)
      room:recover{
        who = player,
        num = 1,
        skillName = skel.name
      }
    end
  end
}
skel:addEffect("active", lanxin)
skel:addEffect(fk.Damaged, lanxin_damage)
-- Fk.generals["mouxusheng"]:addSkill(skel.name)
return skel